Object.defineProperty(exports, "__esModule", {
    value: !0
});

var e = function() {
    var e = {}, t = {};
    return {
        listen: function(n, r) {
            if (n) {
                e[n] = e[n] || [], e[n].push(r);
                var i = t[n];
                i && (i.forEach(function(e) {
                    return e();
                }), t[n] = null);
            }
        },
        emit: function(n) {
            for (var r = this, i = arguments.length, o = Array(i > 1 ? i - 1 : 0), u = 1; u < i; u++) o[u - 1] = arguments[u];
            var f = e[n];
            if (!f || !f.length) return t[n] = t[n] || [], void t[n].push(function() {
                return r.emit.apply(r, [ n ].concat(o));
            });
            f.forEach(function(e) {
                "function" == typeof e && e.apply(void 0, o);
            });
        },
        remove: function(t, n) {
            var r = e[t];
            if (r && r.length) if (n) {
                var i = r.indexOf(n);
                -1 !== i && r.splice(i, 1);
            } else r.length = 0;
        }
    };
}();

exports.default = {
    addListener: function(t, n) {
        return e.listen(t, n), this;
    },
    removeListener: function(t, n) {
        return e.remove(t, n), this;
    },
    emit: function(t) {
        for (var n = arguments.length, r = Array(n > 1 ? n - 1 : 0), i = 1; i < n; i++) r[i - 1] = arguments[i];
        return e.emit.apply(e, [ t ].concat(r)), this;
    },
    removeAllListener: function(t) {
        return e.remove(t), this;
    }
};